package networkcommunication.c1_inetaddress;

import java.net.InetAddress;

public class InetADDressTest {
    public static void main(String[] args) throws Exception {
        //获取以本机ip地址的
       InetAddress IP1= InetAddress.getLocalHost();
        System.out.println(IP1.getHostName());
        System.out.println(IP1.getHostAddress());
//获取指定ip地址
        InetAddress ip2=InetAddress.getByName("www.baidu.com");
        //访问主机名
        System.out.println(ip2.getHostName());
        //访问真实的ip地址
        System.out.println(ip2.getHostAddress());
        //六秒内是否与服务器联通
        System.out.println(ip2.isReachable(6000));
    }
}
